angular.module('start.user.orderpay.ctrl', [])

  .controller('orderpayCtrl', function($scope,$ionicHistory, $ionicPopup, $$UserOrderService, $rootScope, $stateParams, $location, $ionicLoading) {
    console.log("orderpayCtrl");
    $scope.orderId = $stateParams.orderId;


    $scope.subop = function() {
      // A confirm dialog
      $scope.showConfirm();
    };


    $scope.showConfirm = function() {
      var confirmPopup = $ionicPopup.confirm({
        title: '余额支付',
        template: '您确认支付吗？',
        okText: '确定',
        cancelText: '取消'
      });

      confirmPopup.then(function(res) {
        if (res) {
          // 用户支付订单
          $$UserOrderService.changeOrderState($scope.orderId, 101)
            .then(function(res) {
              $ionicLoading.show({
                template: res.msg,
                noBackdrop: true,
                duration: 1500
              });
              $ionicHistory.goBack();
            });
        } else {}
      });
    };


    $scope.calcdateDays = function(start, end) {
      return parseInt((new Date(end).getTime() - new　 Date(start).getTime()) / (86400000));
    };

  });
